<%@ page import="org.wlw.service.IMovieService" %>
<%@ page import="org.wlw.factoy.SimpleFactory" %>
<%@ page import="java.util.List" %>
<%@ page import="org.wlw.models.Movie" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script src="<%=request.getContextPath()%>/static/bootstrap-3.4.1-dist/js/jquery-3.6.0.min.js"></script>
    <script src="<%=request.getContextPath()%>/static/bootstrap-3.4.1-dist/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="<%=request.getContextPath()%>/static/bootstrap-3.4.1-dist/css/bootstrap.min.css">
    <script>
        function confirmOp(url) {
            let c = confirm("该操作不可逆，确定删除吗?")
            if(c) {
                //让页面跳转到url
                window.location.href = url
            }
        }
    </script>
</head>
<body>
<%
    IMovieService movieService = SimpleFactory.getMovieService();
    List<Movie> movies = movieService.list();
%>
    <div class="container">
        <h3>
            <a href="add.jsp" class="btn btn-primary">添加电影</a>&nbsp;
            <a href="list.jsp" class="btn btn-info">列表电影</a>
        </h3>
        <hr>
        <table class="table table-bordered table-striped table-hover">
            <thead>
                <tr>
                    <td>电影标识</td>
                    <td>电影名称</td>
                    <td>电影类型</td>
                    <td>导演</td>
                    <td>主演</td>
                    <td>评分</td>
                    <td>操作</td>
                </tr>
            </thead>
            <tbody>
            <%
            for(Movie m:movies) {
            %>
            <tr>
                <td><%=m.getId()%></td>
                <td><%=m.getName()%></td>
                <td><%=m.getType()%></td>
                <td><%=m.getDirector()%></td>
                <td><%=m.getActor()%></td>
                <td><%=m.getScore()%></td>
                <td>
                    <a href="javascript:confirmOp('delete.jsp?id=<%=m.getId()%>')" class="btn btn-danger">删除</a>
                    <a href="update.jsp?id=<%=m.getId()%>" class="btn btn-warning">更新</a>
                </td>
            </tr>

            <%
            }
            %>
            </tbody>
        </table>
    </div>
</body>
</html>
